package com.jie.swaggerdemo.controller;


import com.jie.swaggerdemo.Model.Book;
import com.jie.swaggerdemo.service.BookService;
import com.jie.swaggerdemo.utils.JsonResponseBody;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @description:书本
 * @author: jie
 * @time: 2022/4/4 21:14
 */
@RestController
@Api(value = "书本管理", tags = {"书本管理"})
@RequestMapping("/book")
public class BookController {

    @Resource(name = "book")
    private BookService bookService;

    JsonResponseBody jsonResponseBody = new JsonResponseBody();

    @ApiResponses({@ApiResponse(code = 400,message = "参数填写错误"),@ApiResponse(code = 200,message = "访问成功")})
    @ApiOperation(value = "查询所有书本信息",
            notes = "查询返回所有书本信息集合",
            produces = "application/json")
    @GetMapping("/queryAll")
    public JsonResponseBody queryAll() {
        jsonResponseBody.setData(bookService.selectAll());
        return jsonResponseBody;
    }

    @ApiOperation(value = "新增书本信息", notes = "新增书本信息", produces = "application/json", consumes = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookName", value = "书本名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "price", value = "书本价格", required = true, dataType = "Double"),
            @ApiImplicitParam(name = "bookType", value = "书本类型", required = true, dataType = "String")
    })
    @GetMapping("/insert")
    public JsonResponseBody insert(Book book) {
        book.setBookId(UUID.randomUUID().toString());
        jsonResponseBody.setStatus(bookService.insert(book));
        return jsonResponseBody;
    }
    @ApiOperation(value = "修改书本信息", notes = "修改书本信息", produces = "application/json", consumes = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookId", value = "书本ID", required = true, dataType = "String"),
            @ApiImplicitParam(name = "bookName", value = "书本名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "price", value = "书本价格", required = true, dataType = "Double"),
            @ApiImplicitParam(name = "bookType", value = "书本类型", required = true, dataType = "String")
    })

    @GetMapping("/update")
    public JsonResponseBody update(Book book) {
        jsonResponseBody.setStatus(bookService.update(book));
        return jsonResponseBody;
    }
}
